let puliginDefsIcon = document.createElement('div')
puliginDefsIcon.style.position = 'absolute'
puliginDefsIcon.style.top = '-22px'
puliginDefsIcon.style.right = '0px'
puliginDefsIcon.style.zIndex = 99
// puliginDefsIcon.style.width = '90px'
// puliginDefsIcon.style = 'position:absolute;top:-22px;right:0;z-index:99;'
window.__deletePlugin = function () {
}
window.__sharePlugin = function () {
}
window.__editPlugin = function () {
}
// onclick="__deletePlugin()"
puliginDefsIcon.innerHTML = `<i style="font-size:16px;color:#000;padding:5px;cursor:pointer" id="del-icon"  class="icon el-icon-close" title="删除"></i></i><i style="font-size:16px;color:#000;padding:5px;cursor:pointer" id="edit-icon" class="icon el-icon-edit-outline" title="编辑"></i>`
let mouseMoveHandlerContent

function mouseMoveHandler() {
  mouseMoveHandlerContent()
}

let mouseLeaveHandlerContent

function mouseLeaveHandler() {
  mouseLeaveHandlerContent && mouseLeaveHandlerContent()
}
var del, edit
puliginDefsIcon.querySelector("#del-icon").addEventListener("click", function(){
  del()
})
puliginDefsIcon.querySelector("#edit-icon").addEventListener("click", function(){
  edit()
})

export default {
  bind: function (el, data) {
    let functionJson = data.value

    el.addEventListener('mouseover', function (e) {
      del = functionJson.deleteDefs
      edit = functionJson.editDefs

      mouseMoveHandlerContent = () => {
        let parentNode = puliginDefsIcon.parentNode
        if (parentNode !== el) {
          el.appendChild(puliginDefsIcon)
        }

      }
      mouseLeaveHandlerContent = () => {
        let parentNode = puliginDefsIcon.parentNode
        if (parentNode === el) {
          el.removeChild(puliginDefsIcon)
        }
      }
      // app页面列表内部不能有图标
      if (functionJson.pluginDefsInfo.parentPlugin === 'pageTable') {
        return false
      } else {
        e.stopPropagation()
        mouseMoveHandler()
        puliginDefsIcon.removeEventListener('mouseover', mouseMoveHandler)
        puliginDefsIcon.removeEventListener('mouseleave', mouseLeaveHandler)
        puliginDefsIcon.addEventListener('mouseover', mouseMoveHandler)
        puliginDefsIcon.addEventListener('mouseleave', mouseLeaveHandler)
      }

      return false
    }, false)
    el.addEventListener('mouseleave', mouseLeaveHandler)

  },
  unbind(el) {
    puliginDefsIcon.removeEventListener('mouseover', mouseMoveHandler)
    puliginDefsIcon.removeEventListener('mouseleave', mouseLeaveHandler)
  }

}
